import java.util.Stack;

public class Main {
    Stack<Integer> stack = new Stack<>();
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}
//力扣20. 有效的括号
class Solution {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();

        int len = s.length();

        for (int i = 0; i < len; i++) {

            if (s.charAt(i) == '(' || s.charAt(i) == '{' || s.charAt(i) == '['){
                stack.push(s.charAt(i));
            }
            else {
                if(stack.empty()){
                    return false;
                }
                //右括号
                if( (s.charAt(i) == ')' && stack.peek() == '(') ||
                        (s.charAt(i) == '}' && stack.peek() == '{') ||
                        (s.charAt(i) == ']' && stack.peek() == '[') ){
                    stack.pop();
                }else {
                    return false;
                }
            }

        }
        if(!stack.empty())
            return false;
        return true;
    }
}